/**
 * 
 */
package com.thon.dao.project.impl;


import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.thon.dao.project.ProjectAttentionDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.Project;
import com.thon.entity.project.ProjectAttention;
import com.thon.entity.user.User;

/**
 * @file ProjectAttentionDaoImpl.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年10月11日 上午11:33:10
 * @description: TODO
 */
@Repository
public class ProjectAttentionDaoImpl extends AbstractDao<ProjectAttention> implements ProjectAttentionDao{
	
	public ProjectAttentionDaoImpl(){
		super(ProjectAttention.class);
	}

	@Override
	public Long countAttention(int projectId) {
		
		String queryString = "SELECT COUNT(*) FROM ProjectAttention pa WHERE pa.project.id = ?";
		return count(queryString, projectId);
	}

	@Override
	public Long hasAttention(Integer userId, Integer projectId) {
		
		String queryString = "SELECT COUNT(*) FROM ProjectAttention WHERE userId=? AND project.id=? ";
		
		return count(queryString, userId,projectId);
	}

	@Override
	public Integer getProjectAttention(Integer userId,Integer projectId) {
		String queryString = "select id from ym_project_attentions where user_id=? and project_id=? ";
		Object object = findOneBySQL(queryString, userId,projectId);
		Integer projectAttentionId = (Integer)object;
		return projectAttentionId;
	}

	@Override
	public List<ProjectAttention> listAttentionByPro(Project project) {
		String queryString = "from ProjectAttention where project = ?";
		return findList(queryString, null, project);
	}

	@Override
	public Page<ProjectAttention> findProjectAttentionByUser(Integer userId,
			Page<ProjectAttention> page) {
		String queryString="FROM ProjectAttention pa WHERE pa.userId=?";
		return findPage(page, queryString, userId);
	}
}
